package cn.fan.redis;

import cn.fan.mapper.FundFollowMapper;
import cn.fan.pojo.FundFollow;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class FundFollowRedis {
    private static final String USERFOLLOW = "userfollow";
    private static final String USERFOLLOWLIST = "userfollow:list";

    @Autowired
    private FundFollowMapper fundFollowMapper;

    @Cacheable(value = USERFOLLOW ,key = "#id")
    public FundFollow getById(int id){
        return fundFollowMapper.selectById(id);
    }

    @CachePut(value = USERFOLLOW ,key = "#id")
    public FundFollow putById(int id){
        return fundFollowMapper.selectById(id);
    }

    @CachePut(value = USERFOLLOW ,key = "#id")
    public FundFollow putById(int id,FundFollow fundFollow){
        return fundFollow;
    }

    @CacheEvict(value = USERFOLLOW ,key = "#id")
    public void delete(int id){}

    // list
    @Cacheable(value = USERFOLLOWLIST ,key = "#userId")
    public List<FundFollow> getList(long userId){
        LambdaQueryWrapper<FundFollow> queryWrapper = new LambdaQueryWrapper<FundFollow>();
        queryWrapper.eq(FundFollow::getUserid,userId);
        List<FundFollow> list =fundFollowMapper.selectList(queryWrapper);
        return list;
    }

    @CachePut(value = USERFOLLOWLIST,key = "#userId")
    public List<FundFollow> putList(long userId){
        LambdaQueryWrapper<FundFollow> queryWrapper = new LambdaQueryWrapper<FundFollow>();
        queryWrapper.eq(FundFollow::getUserid,userId);
        List<FundFollow> list =fundFollowMapper.selectList(queryWrapper);
        return list;
    }

    @CachePut(value = USERFOLLOWLIST,key = "#userId")
    public List<FundFollow> putList(List<FundFollow> fundFollows){
        return fundFollows;
    }

    @CacheEvict(value = USERFOLLOWLIST,key = "#userId")
    public void deleteList(){}
}
